<template>
  <div>
      <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
        <!-- 搜索与添加区域 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getOrdersList">
            <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 用户列表区域 -->
      <el-table :data="ordersList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" width="110px">
            <template slot-scope="scope">
                <el-tag type="warning" v-if="scope.row.order_pay === '0'">未付款</el-tag>
                <el-tag type="success" v-else>已付款</el-tag>
            </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send" width="110px"></el-table-column>
        <el-table-column label="下单时间">
            <template slot-scope="scope" >
            {{scope.row.create_time | dateFormat}}
            </template>
        </el-table-column>
        <el-table-column label="操作" width="120px">
          <!-- eslint-disable-next-line vue/no-unused-vars -->
          <template slot-scope="scope">
            <!-- 修改按钮 -->
            <!-- <el-tooltip :enterable="false" effect="dark" content="修改地址" placement="top-start"> -->
            <el-button title="编辑地址" type="primary" icon="el-icon-edit" size="mini" alt="修改地址" @click="editAdress(scope.row)"></el-button>
            <!-- </el-tooltip> -->
            <!-- 按钮 -->
            <el-button title="查看物流" type="success" icon="el-icon-location" size="mini" @click="showPostDialog"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum" 
      :page-sizes="[5, 10, 20, 50]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-card>
    <!-- 修改的对话框 -->
    <el-dialog title="编辑地址" :visible.sync="editDialogVisible" width="50%" @close="closeDialog()">
      <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="150px">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="editForm.address1"
            :options="cityData"
            @change="cascaderChange"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editForm.address1"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitEditDialog">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息的对话框 -->
    <el-dialog title="物流进度" :visible.sync="postDialogVisible" 
    width="50%">
        <el-timeline>
            <el-timeline-item
            v-for="(activity, index) in postData"
            :key="index"
            :timestamp="activity.time">
            {{activity.context}}
            </el-timeline-item>
        </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data() {
    return {
        queryInfo:{
            query:'',
            pagenum:1,
            pagesize:5
        },
        ordersList:[],
        total:0,
        editDialogVisible:false,
        editForm:{
            address1:[],
            address2:''
        },
        editFormRules:{
            address1:[{ required: true, message: '请输入', trigger: 'blur' }],
            address2:[{ required: true, message: '请输入', trigger: 'blur' }]
        },
        cityData,
        postDialogVisible:false,
        postData:[]
    }
  },
  created() {
      this.getOrdersList()
  },
  methods: {
    async getOrdersList(){
       const {data:res} = await this.$http.get('orders',{params:this.queryInfo})
       if(res.meta.status != 200) return this.$message.error('数据获取失败')
       //this.$message.success('数据获取成功')
       console.log(res.data)
       this.ordersList = res.data.goods;
       this.total = res.data.total;
    },
    handleSizeChange(val){
        this.queryInfo.pagesize = val;
        this.getOrdersList();
    },
    handleCurrentChange(val){
         this.queryInfo.pagenum = val;
        this.getOrdersList();
    },
    closeDialog(){
        this.$refs.editFormRef.resetFields()
    },
    submitEditDialog(){
        this.editDialogVisible = false
    },
    editAdress(){
        this.editDialogVisible = true;

    },
    cascaderChange(){
        console.log(this.editForm.address1)
    },
    async showPostDialog(){
        const {data:res} = await this.$http.get(`/kuaidi/1106975712662`)
        if(res.meta.status != 200) return this.$message.error('物流信息获取失败')
        this.postData = res.data;
        console.log(this.postData)
        this.postDialogVisible = true;
    }
  },
  components: {

  }
}
</script>

<style lang='less' scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';
.el-cascader{
    width: 100%
}
</style>